<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检测变量是否是布尔型</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.is-bool" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">is_bool</h1>
     <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">is_bool</span> &mdash; <span class="dc-title">
      检测变量是否是布尔型
     </span></p>

    </div>
    <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.is-bool-unknown-unknown-seealsq">
     <h3 class="title">描述</h3>
     <div class="methodsynopsis dc-description">
       <span class="methodname"><strong>is_bool</strong></span>
        ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>
      ) : <span class="type">bool</span></div>

     <p class="para rdfs-comment">
      如果 <code class="parameter">var</code>
      是 <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span> 则返回 <strong><code>TRUE</code></strong>。
     </p>
     <p class="para">
      <div class="example" id="example-6361">
      <p><strong>Example #1 <span class="function"><strong>is_bool()</strong></span> 示例</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;因为&nbsp;$a&nbsp;是布尔型，所以结果为真<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">is_bool</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Yes,&nbsp;this&nbsp;is&nbsp;a&nbsp;boolean"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;因为&nbsp;$b&nbsp;不是布尔型，所以结果为非真<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">is_bool</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Yes,&nbsp;this&nbsp;is&nbsp;a&nbsp;boolean"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
       </div>

      </div>
     </p>
     <p class="para">
     参见 
     <span class="function"><a href="is_array.html" class="function">is_array()</a></span>、<span class="function"><a href="is_float.html" class="function">is_float()</a></span>、<span class="function"><a href="is_int.html" class="function">is_int()</a></span>、<span class="function"><a href="is_integer.html" class="function">is_integer()</a></span>、<span class="function"><a href="is_string.html" class="function">is_string()</a></span>
     和 <span class="function"><a href="is_object.html" class="function">is_object()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>